package Main;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

import Equasion.Equasion;


public class Main extends JPanel implements ActionListener
{
	private static final long serialVersionUID = 1L;
	public static final int windowXSize = 500, windowYSize = 550;
	public static int xMin = -10,yMin = -10,xMax = 10,yMax = 10;
	private Graph graph;
	private JTextField inputField;
	public static ArrayList<Equasion> equasionList = new ArrayList<Equasion>();
	
	public static void main(String args[])
	{
		EventQueue.invokeLater(new Runnable() { 
			
			@Override
			public void run() {
				JFrame frame = new JFrame();
				frame.setSize(windowXSize,windowYSize);
				frame.setVisible(true);
				
				Main f = new Main();
				frame.add(f);
			}
		});
	}
	public Main(){
		setLayout(new BorderLayout());
		
		graph = new Graph();
		add(graph);
		
		inputField = new JTextField();
		add(inputField,BorderLayout.SOUTH);
		
		inputField.addActionListener(this);
	}
	
	
	@Override
	public void actionPerformed(ActionEvent e) {
		equasionList.clear();
		parseInput();
		graph = new Graph();
		repaint();
	}
	
	private void parseInput()
	{
		String[] inputParts = inputField.getText().split(",");
		for(String s:inputParts)
			s.trim();
		
		if(inputParts[0].equalsIgnoreCase("graph"))
		{
			for(int i = 1;i<inputParts.length;i++)
			{
				equasionList.add(new Equasion(inputParts[i]));
			}
		}
		else
		{
			for(int i = 0;i<inputParts.length;i++)
			{
				equasionList.add(new Equasion(inputParts[i]));
			}
		}
	}
}
